home *** CD-ROM | disk | FTP | other *** search
- unit Tcselcom;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, AdPort;
-
- type
- TComSelectForm = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- OkBtn: TBitBtn;
- AbortBtn: TBitBtn;
- Ports: TGroupBox;
- Com1Btn: TRadioButton;
- Com2Btn: TRadioButton;
- Com3Btn: TRadioButton;
- Com4Btn: TRadioButton;
- Com5Btn: TRadioButton;
- Com6Btn: TRadioButton;
- Com7Btn: TRadioButton;
- Com8Btn: TRadioButton;
- ThePort: TApdComPort;
- procedure FormCreate(Sender: TObject);
- private
- PortButtons : array[1..8] of TRadioButton;
-
- function ValidComPort(ComNumber : Word) : Boolean;
- {-Return TRUE if ComNumber represents a valid port}
-
- public
- function SelectedCom : String;
- end;
-
- implementation
-
- {$R *.DFM}
-
- procedure TComSelectForm.FormCreate(Sender: TObject);
- var
- I : Word;
- E : Boolean;
-
- begin
- PortButtons[1] := Com1Btn;
- PortButtons[2] := Com2Btn;
- PortButtons[3] := Com3Btn;
- PortButtons[4] := Com4Btn;
- PortButtons[5] := Com5Btn;
- PortButtons[6] := Com6Btn;
- PortButtons[7] := Com7Btn;
- PortButtons[8] := Com8Btn;
-
- E := False;
- for I := 1 to 8 do
- if not ValidComPort(I) then
- PortButtons[I].Enabled := False
- else begin
- PortButtons[I].Enabled := True;
-
- if not E then begin
- PortButtons[I].Checked := True;
- E := True;
- end;
- end;
- end;
-
- function TComSelectForm.ValidComPort(ComNumber : Word) : Boolean;
- {-Return TRUE if ComNumber represents a valid port}
- begin
- Result := True;
-
- try
- ThePort.ComNumber := ComNumber;
- ThePort.Open := True;
- ThePort.Open := False;
- except
- Result := False;
- end;
- end;
-
- function TComSelectForm.SelectedCom : String;
- var
- I : Word;
-
- begin
- Result := 'COM1';
- for I := 1 to 8 do
- if PortButtons[I].Checked then begin
- Result[4] := Char(I + Ord('0'));
- Exit;
- end;
- end;
-
- end.
-
-